//
//  KZMistakesCoachingVC.m
//  lg_zhinengbeikao_english
//
//  Created by 朱凯 on 2018/12/20.
//  Copyright © 2018年 zhukai. All rights reserved.
//

#import "KZMistakesCoachingVC.h"
#import "KZWaveCountView.h"
// view
#import "KZMistakesCoachingHeaderView.h"

// cell
#import "KZMistakesCoachingSubjectTypeCell.h"

@interface KZMistakesCoachingVC () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *table;
@property (nonatomic, strong) NSArray *subjectTypes;
@property (nonatomic, strong) KZMistakesCoachingHeaderView *headerView;
@end

@implementation KZMistakesCoachingVC

#pragma mark - view cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 题型数组
    _subjectTypes = @[@"单选题", @"完型选择", @"翻译题", @"阅读理解", @"完形填空", @"作文"];
    
    [self createTableView];
}
- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    [self setNaviAttributeWithTranslucent:true stateBarLightContent:true];
    
    // 监控waveView的动画
    [[NSNotificationCenter defaultCenter] postNotificationName:@"KZWaveCountViewStartAnimation" object:nil];
}
- (void)viewWillDisappear:(BOOL)animated {
    
    [super viewWillDisappear:animated];
    
    // 监控waveView的动画
    [[NSNotificationCenter defaultCenter] postNotificationName:@"KZWaveCountViewStopAnimation" object:nil];
}

#pragma mark - UITableViewDelegate
- (void)createTableView {
    
    self.table = [[UITableView alloc] init];
    self.table.backgroundColor = kBgColor;
    self.table.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.table.delegate = self;
    self.table.dataSource = self;
    [self.view addSubview:self.table];
    [self.table mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(0, 0, 0, 0)).priorityMedium();
        if (@available(iOS 11.0, *)) {
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);;
            make.left.equalTo(self.view.mas_safeAreaLayoutGuideLeft);
            make.right.equalTo(self.view.mas_safeAreaLayoutGuideRight);
        }
    }];
    
    [self.table registerClass:[KZMistakesCoachingSubjectTypeCell class] forCellReuseIdentifier:@"subjectTypeCell"];
    
    _headerView = [[KZMistakesCoachingHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, H(200))];
    _table.tableHeaderView = _headerView;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _subjectTypes.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    KZMistakesCoachingSubjectTypeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"subjectTypeCell"];
    cell.typeLabel.text = _subjectTypes[indexPath.row];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 44;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 10;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return UIView.new;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return UIView.new;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:false];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    // 设置header背景的拉伸
    _headerView.offset = scrollView.contentOffset.y;
}

@end
